#@layoutT("采购单")
#define main()
	#@formStart()
		#@queryStart('单据编号')
		   <input type="search" name="userCode" autocomplete="off" class="layui-input" placeholder="单据编号"/>
		#@queryEnd()
		#@queryStart('开单人')
		<input type="search" name="userCode" autocomplete="off" class="layui-input" placeholder="开单人"/>
		#@queryEnd()
		#@queryStart('开始时间')
		   <input id="begin_time" type="search" name="userName" autocomplete="off" class="layui-input" placeholder="开始时间"/>
		#@queryEnd()
		#@queryStart('结束时间')
		<input id="end_time" type="search" name="userName" autocomplete="off" class="layui-input" placeholder="结束时间"/>
		#@queryEnd()
		#@queryStart('单据状态')
		   <select name="orgId" class="layui-input" lay-search>
		   		<option value="">---请选择状态---</option>
		   		#for(data:orgList)
       			<option value="#(data.value??)">#(data.text??)</option>
       			#end
		   </select>
		#@queryEnd()
		
	#@formEnd()

	<div class='layui-row f-index-toolbar'>
		<div class='layui-col-xs12'>
			<div class="layui-btn-group">
				<button id='addBtn_' class="layui-btn layui-btn-normal layui-btn-sm">
					<i class="layui-icon">&#xe608;</i> 新增
				</button>
				<button id='deleteBtn_' class="layui-btn  layui-btn-normal layui-btn-sm">
					<i class="layui-icon">&#xe640;</i> 删除
				</button>
				<button id='approve' class="layui-btn layui-btn-normal layui-btn-sm">
					<i class="layui-icon">&#xe605;</i> 确认
				</button>
				<button id='refuse' class="layui-btn  layui-btn-normal layui-btn-sm">
					<i class="layui-icon">&#x1006;</i> 退回
				</button>
			</div>
		</div>
	</div>
	<div class="layui-row  f-index-toolbar">
			<div class="layui-col-xs12">
   				<table id="maingrid" lay-filter="maingrid"></table>
   			</div>
   	</div>
   	
   	<!-- 	每行的操作按钮 -->
	<script type="text/html" id="bar_maingrid">
		<a class="layui-btn layui-btn-xs" lay-event="showOrderDetailList">订单项</a>
		<a class="layui-btn layui-btn-xs" lay-event="showOutcomeList">付款明细</a>
		<a class="layui-btn layui-btn-xs" lay-event="review">预览</a>
  		<a class="layui-btn layui-btn-xs" lay-event="edit">修改</a>
		<a class="layui-btn layui-btn-xs" lay-event="del">删除</a>
	</script>
#end

<!-- 时间控件 -->
#define layuiFunc()
    laydate.render({
        elem: '#begin_time',
        type: 'datetime'
    });
    laydate.render({
        elem: '#end_time',
        type: 'datetime'
    });
#end

#define js()
<!-- 分页表格 -->
<script>
	$(function () {
        getTable();
    })

	function getTable(){
        gridArgs.title='采购单列表';
        gridArgs.dataId='order_id';
        gridArgs.deleteUrl='#(path)/erp/order/purchase/delete';
        gridArgs.updateUrl='#(path)/erp/order/purchase/edit?orderId=';
        gridArgs.addUrl='#(path)/erp/order/purchase/add';
        gridArgs.gridDivId ='maingrid';
        gridArgs.approveUrl = '#(path)/erp/order/purchase/approve';
        gridArgs.approveBtn='#approve';
        gridArgs.refuseUrl = '#(path)/erp/order/purchase/refuse';
        gridArgs.refuseBtn='#refuse';
        initGrid({id : 'maingrid'
            ,elem : '#maingrid'
            ,cellMinWidth: 80
            ,cols : [ [
                {title: '主键',field : 'order_id',width : 35,checkbox : true},
                {title:'序号',type:'numbers',width:35},
                {title: '供应商', field: 'supplier_name' },
                {title: '开单人', field: 'originator_name'},
                {title: '经手人', field: 'hander_name'},
                {title: '确认人', field: 'confirmer_name'},
                {title: '开单时间', field: 'originat_time'},
                {title: '计划到货时间', field: 'plan_time'},
                {title: '实际到货时间', field: 'actual_time'},
                {title: '结账方式', field: 'settle_way'},
                {title: '总金额', field: 'total_amount'},
                {title: '是否含发票', field: 'contain_bill'},
                {title: '税率', field: 'tax_rate'},
                {title: '状态', field: 'status'},
                {title: '操作',fixed:'right',width : 300,align : 'left',toolbar : '#bar_maingrid'} // 这里的toolbar值是模板元素的选择器
            ] ]
            ,url:"#(path)/erp/order/purchase/list"
            ,where:{"object":"purchase_order","primaryKey":gridArgs.dataId}
            ,searchForm : 'searchForm'
        },{
            showOrderDetailList:showOrderDetailList,
			review:review,
			showOutcomeList:showOutcomeList
        });
	}

	function review(obj) {
        var data=obj.data;
        var id=data[gridArgs.dataId];
        openDialog("销售单预览窗口","#(path)/erp/order/purchase/review?orderId="+id,false,null,null,null);
    }

    function showOrderDetailList(obj){
        var data=obj.data;
        var id=data[gridArgs.dataId];
        openDialog("订单明细窗口","#(path)/erp/order/purchaseDetail/index?orderId="+id,false,null,null,null);
    }

    function showOutcomeList(obj){
        var data=obj.data;
        var id=data[gridArgs.dataId];
        openDialog("付款明细窗口","#(path)/erp/order/outcomeDetail/index?orderId="+id,false,null,null,null);
    }
</script>
#end

 
 